package com.ruoyi.web.controller.edh;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.edh.domain.EdhCategories;
import com.ruoyi.edh.domain.vo.EdhCategoriesVo;
import com.ruoyi.edh.service.IEdhCategoriesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 易订货-分类Controller
 *
 * @author xxx
 * @date 2020-09-02
 */
@RestController
@RequestMapping("/edh/categories")
@Api(description = "易订货-分类")
public class EdhCategoriesController extends BaseController {
    @Autowired
    private IEdhCategoriesService edhCategoriesService;

    /**
     * 查询一级分类
     *
     * @return
     */
    @GetMapping("/topCategoriesList")
    @ApiOperation("易订货-一级分类列表")
    public AjaxResult selectEdhTopCategoriesList() {
        List<EdhCategories> edhCategories = edhCategoriesService.selectEdhTopCategoriesList();
        if (0 >= edhCategories.size()) {
            return AjaxResult.error("一级分类数据为空");
        }
        return AjaxResult.success("查询成功", edhCategories);
    }

    ;

    /**
     * 查询全部分类
     *
     * @return
     */
    @GetMapping("/allCategoriesList")
    @ApiOperation("易订货-全部分类列表")
    public AjaxResult selectEdhAllCategoriesList() {
        List<EdhCategoriesVo> edhCategoriesVos = edhCategoriesService.selectEdhAllCategoriesList();
        if (0 >= edhCategoriesVos.size()) {
            return AjaxResult.error("全部分类数据为空");
        }
        return AjaxResult.success("查询成功", edhCategoriesVos);
    }

    ;

    /**
     * @description:查询热卖专区分类列表
     * @return: 分类信息list
     * @author: 梁东宸
     * @time: 2020/10/15 10:23 上午
     */
    @GetMapping("/hotCategoriesList")
    @ApiOperation("易订货-热卖分类列表")
    public AjaxResult selectHotCategoriesList() {
        List<EdhCategories> edhCategories = edhCategoriesService.selectHotCategoriesList();
        if (0 >= edhCategories.size()) {
            return AjaxResult.error("全部分类数据为空");
        }
        return AjaxResult.success("查询成功", edhCategories);
    }

    /**
     * 查询易订货-分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:categories:list')")
    @GetMapping("/list")
    @ApiOperation("易订货-分类列表")
    public TableDataInfo list(EdhCategories edhCategories) {
        startPage();
        List<EdhCategories> list = edhCategoriesService.selectEdhCategoriesList(edhCategories);
        return getDataTable(list);
    }

    /**
     * 导出易订货-分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:categories:export')")
    @Log(title = "易订货-分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出易订货-分类列表")
    public AjaxResult export(EdhCategories edhCategories) {
        List<EdhCategories> list = edhCategoriesService.selectEdhCategoriesList(edhCategories);
        ExcelUtil<EdhCategories> util = new ExcelUtil<EdhCategories>(EdhCategories.class);
        return util.exportExcel(list, "categories");
    }

    /**
     * 获取易订货-分类详细信息
     */
    @GetMapping("/{id}")
    @ApiOperation("获取易订货-分类详细信息")
    public AjaxResult getInfo(@PathVariable(value = "id") Long id) {
        return AjaxResult.success(edhCategoriesService.selectEdhCategoriesById(id));
    }

    /**
     * 新增易订货-分类
     */
    @PreAuthorize("@ss.hasPermi('system:categories:add')")
    @Log(title = "易订货-分类", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增易订货-分类")
    public AjaxResult add(@RequestBody EdhCategories edhCategories) {
        return toAjax(edhCategoriesService.insertEdhCategories(edhCategories));
    }

    /**
     * 修改易订货-分类
     */
    @PreAuthorize("@ss.hasPermi('system:categories:edit')")
    @Log(title = "易订货-分类", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改易订货-分类")
    public AjaxResult edit(@RequestBody EdhCategories edhCategories) {
        return toAjax(edhCategoriesService.updateEdhCategories(edhCategories));
    }

    /**
     * 删除易订货-分类
     */
    @PreAuthorize("@ss.hasPermi('system:categories:remove')")
    @Log(title = "易订货-分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove")
    @ApiOperation("删除易订货-分类")
    public AjaxResult remove(@RequestParam("ids") Long[] ids) {
        return toAjax(edhCategoriesService.deleteEdhCategoriesByIds(ids));
    }
}
